<?php
 class ZhaopinAction extends CommonAction{
 	
 	 private  $table_name;
   	 function __construct(){
   	 	
   	 	$this->table_name = "Zhaopin";
   	 	parent::__construct();
   	 }
	

  	function  index(){

					import('ORG.Util.Page');

					$count=M($this->table_name)->count();// 查询总数据记录

					$Page = new Page($count,C('PAGESIZE'));

					$show= $Page->show();

	                $temp = M($this->table_name);
	                if(isset($_POST['keywords'])){
	                	$map['title'] = array('like','%'.$_POST['keywords'].'%');
	                	 $temp =$temp->where($map);
	                }

	                $temp =$temp->order("createtime DESC")->limit($Page->firstRow.','.$Page->listRows)->select();
	                foreach($temp as $v){
						$v['uname'] = M('user')->where('uid='.$v['uid'])->getField('username');
						$v['city'] = M('city')->where(array('id'=>$v['cityid']))->getField("city");
						$list[]=$v;
					}
	                   
	                $this->assign("list",$list);

					$this->assign("page",$show);

                    $this->display();
       }

       function add(){
  	  	
   	  	if(isset($_POST['submit'])){
   	  	     $data = $_POST;
           $data['createtime']=mktime();
           $data['status']= 1 ;
   	  	    if(M($this->table_name)->add($data)){
   	  	    	$this->success("操作成功！",U('index'));
   	  	    }else{
   	  	    	
   	  	    	$this->error("操作失败");
   	  	    }
   	  	}else{
   	  		$this->list =M($this->table_name."Cate")->select();
   	  		$this->display();
   	  	}
       	
       }

  	   /**

  	    * 

  	    * 编辑文章

  	    */

    	function  edit(){
	              $id= htmlspecialchars($_GET['id']);
	              if(is_numeric($id)){
	              	  if(isset($_POST['submit'])){
	              	  	  $data = $_POST;
	              	  	 // $data['createtime']=mktime();
                          $data['cityid'] = I('post.city');
	              	  	  M($this->table_name)->where("id=".$id)->save($data);
	              	  	  $this->success("更新成功！",U('index'));
	              	  }else{
                          $province = M('City')->where("status=0 AND province !='' ")->select();
                          $this->assign("province",$province);

	              	  	$this->list =M("category")->select();
	              	  	$this->li =M($this->table_name)->where("id=".$id)->find();
	              	  	$this->display();
	              	  }
	              	
	              }
  	 }


  	 /**

  	  * 删除

  	  * 

  	  */
  	  

  	 function del(){
	        $qstr = $_GET['qstr'];
	     
  		  	$data=M($this->table_name);  		  
			if(isset($qstr)){
			   $arr=explode(",",$qstr);

			   foreach($arr as $val){

			     $data->where("id=$val")->delete();
			       
			   }
			   $this->success("删除成功！",U('index'));			

			}else{

			  if(isset($_GET['id'])){

			  $data->where("id=".$_GET['id'])->delete();

			   $this->success("删除成功！",U('index'));

			  }else{

			   $this->error("请选择要删除的ID");

			  }

			}

  	 }
	 

	 
	 
	 function shenhe(){

  	   	   M('Zhaopin')->where("id=".$_GET['id'])->setField('status', 1);
		   $this->redirect('index');

  	   	   //$this->success("操作成功！",U('index'));
		   
  	   }

  	 function read(){
  	 	$id= htmlspecialchars($_GET['id']);
	              if(is_numeric($id)){
  	 					$li =M($this->table_name)->where("id=".$id)->find();
  	 					$cityname = M('city')->where('id='.$li['cityid'])->getField('city');
  	 					$username = M('User')->where('uid='.$li['uid'])->getField('username');
  	 					$this->assign('li',$li);
  	 					$this->assign('username',$username);
  	 					$this->assign('cityname',$cityname);
	              	  	$this->display();
	              }
  	 	
  	 }
 }
?>